package com.lagou.edu.controller;

import com.lagou.edu.dao.ResumeDao;
import com.lagou.edu.pojo.Resume;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/resume")
public class ResumeController {
    @Autowired
    private ResumeDao resumeDao;

    @ResponseBody
    @RequestMapping("/findAll")
    public List<Resume> queryAll() throws Exception {
        return resumeDao.findAll();
    }

    @ResponseBody
    @RequestMapping("/delete")
    public Result delete(Long id) throws Exception {
        resumeDao.deleteById(id);
        return Result.buildSuccessResult();
    }

    @ResponseBody
    @RequestMapping("/save")
    public Result save(@RequestBody Resume resume) throws Exception {
        resumeDao.save(resume);
        return Result.buildSuccessResult();
    }

    @RequestMapping("/list")
    public String list() throws Exception {
        return "list";
    }

    public static class Result {
        private Boolean success;

        public static Result buildSuccessResult() {
            Result result = new Result();
            result.setSuccess(true);
            return result;
        }

        public Boolean getSuccess() {
            return success;
        }

        public void setSuccess(Boolean success) {
            this.success = success;
        }
    }
}
